﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class cookie : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //创建了一个cookie的对象，名字叫：mycookie
            HttpCookie cookie = new HttpCookie("mycookie");
            cookie.Value = "helloworld";
            //设置有效期在一天后过期
            cookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(cookie);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            HttpCookie cookie=Request.Cookies["mycookie"];
            if(cookie != null)
            {
                string value=cookie.Value;
                Response.Write(value);
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            HttpCookie cookie = new HttpCookie("mycookie");
            cookie.Value = "helloworld";
            cookie.Expires= DateTime.Now.AddDays(-1);
            Response.Cookies.Add(cookie);
        }
    }
}